 var ua = navigator.userAgent.toLowerCase();
    var isWeixin = ua.indexOf('micromessenger') != -1;
    var isAndroid = ua.indexOf('android') != -1;
    var isIos = (ua.indexOf('iphone') != -1) || (ua.indexOf('ipad') != -1);
    $("#answerBt").hide();
   
    var result = {
        "msg": "成功!",
        "code": 0,
        "data": {
            "user": {
                "userid": "" //用户的userid
            },
            "article": {
                "title": "", //文章标题
                "content": "", //文章内容
                "shareUrl": "", //分享的url
                "note": "", //分享的标题
                "url": "", //原文地址
                "praiseNum": "" //爱心数
            },
            "question": {
                "titile": "问题名字", //问题
                "answers": [{
                    "answer": "答案一",
                    "answerId": 123
                }, {
                    "answer": "答案二",
                    "answerId": 456
                }, {
                    "answer": "答案三",
                    "answerId": 456
                }, {
                    "answer": "答案四",
                    "answerId": 456
                }]
            },
            "isFirst": "", //是否是第一次答题 1是 0否
            "isPraise": "", //是否已经点过爱心 1是 0否
            "isAllow": "" //是否允许答题  1 允许，0不允许

        }
    }
    var is_first = true;
   
    $(function() {

        if (is_first) {
            beginView(result.data.question);
        } else {
            $("#float").hide();
            $("#answerBt").show();
        }
         //alert(document.body.clientHeight);
        if (document.body.clientHeight < 481&&isIos) {
         // alert("成功");
            $("#float_view").css("width", "70%");
            $("#float_view").css("margin-left", "15%");
            $("#float_view").css("margin-top", "10%");

        } else {

        }

    })

    function beginView(result) {
      
        var listHtml = "";
        listHtml += "<ul>";
        var imgArr = new Array("../imgs/A.png", "../imgs/B.png", "../imgs/C.png", "../imgs/D.png");
        for (var i = 0; i < result.answers.length; i++) {
            listHtml += "<li><img src=" + imgArr[i] + "><label>" + result.answers[i].answer + "</label></li>"
        }
        listHtml += "</ul>";
        var floatHtml = "<div id='float_view'><img src='../imgs/gifts.png'><div id='content'><div class='title'>" + result.titile + "</div>" + listHtml + "<div class='chickBt'><span>寻找答案</span></div></div></div>";
        $("#float").empty().append(floatHtml);
        stopMove();

    }

    $("#float").click(function() {

        if (is_first) {
            is_first = false;
            var mhtml = " <div id='progress'><div id='bar'></div></div>";
            $("#float").append(mhtml);
            $("#bar").animate({
                marginLeft: "-100%"
            }, 1000);
            setTimeout(function() {
                $("#float").hide();
                $("#answerBt").show();
            }, 1000);
            moveAction();
        } else {

        }

    })
    $("#answerBt").click(function() {
        var listHtml = "";
        listHtml += "<ul>";
        var imgArr = new Array("../imgs/A_1.png", "../imgs/B_1.png", "../imgs/C_1.png", "../imgs/D_1.png");
        for (var i = 0; i < result.data.question.answers.length; i++) {
            listHtml += "<li value=" + i + "><div><img src=" + imgArr[i] + "><span>" + result.data.question.answers[i].answer + "</span></div></li>"
        }
        listHtml += "</ul>";
        var floatHtml = "<div id='answer_view'><img src='../imgs/pic_top.png'><div id='contents'><div class='titles'>" + result.data.question.titile + "</div>" + listHtml + "<div class='sublimtBt'>提交</div><div style='height:10px;'></div></div></div>";
        $("#float").empty().append(floatHtml);
        $("#float").show();
        if (document.body.clientHeight < 481&&isIos) {
            $("#answer_view").css("width", "70%");
            $("#answer_view").css("margin-left", "15%");
            $("#answer_view").css("margin-top", "10%");

        } else {

        }

        stopMove();
        $("#answer_view #contents ul li").click(function() {
            console.log($(this).val());
            $(this).css("background", "#f3f7f9");
            $(this).css("color", "#ff5d44");
            $(this).siblings().css("background", "white");
            $(this).siblings().css("color", "#212a2f");
        })
        $(".sublimtBt").click(function() {
            console.log("提交答案");
            successAction();
             //errorAction();
        })
    })

    function errorAction() {
        var errorHtml = " <div id='errorView'><img src='../imgs/error.png'><div class='right_msg'>你484洒</div><div class='right_mes'>账户<span>+0元</span></div><div class='continue'>分享获得一次答题机会</div><div style='height:10px;'></div></div>";
        $("#float").empty().append(errorHtml);
        stopMove();
        $(".continue").click(function() {
            var data = {
                "url": "https://www.baidu.com",
                "title": "小麦分享",
                "content": "这是一个分享内容"
            }
            if (isAndroid) {
                //安卓来源

                xmapp.shareXiaoMai(JSON.stringify(data), callBack);

               // xmapp.exitWeb();
            }
            else if (isIos) {
                //IOS来源

                shareXiaoMai(JSON.stringify(data), callBack);
            }
            else{
                
            }

        })
    }
    var callBack = function(data) {

        alert(data.msg);

    }

    function successAction() {
        var successHtml = " <div id='rightView'><img src='../imgs/right.png'><div class='type'>RMB</div><div class='price'>0.5</div><div class='right_msg'>哎呀我去,这都能答对</div><div class='right_mes'>账户<span>+0.5元</span></div><div class='notes'>继续做任务,还有奖励!</div><div class='continue'>继续拿奖励</div><div style='height:10px;'></div></div>"
        $("#float").empty().append(successHtml);
        stopMove();
        $(".continue").click(function() {
            if (isAndroid) {

                xmapp.exitWeb();
            }
            else if (isIos) {
                //IOS来源
                exitWeb();
                
            }
            else{
                
            }

        })
    }

    function hander() {
        event.preventDefault();
    }

    function moveAction() {
      
        document.body.removeEventListener('touchmove', hander, false);
    }

    function stopMove() {
        
        document.body.addEventListener('touchmove', hander, false);

    }